package ovm.management;

import ovm.entity.EntityFormPropertiesEntity;
import ovm.entity.EntityTablePropertiesEntity;
import ovm.management.administration.factory.EntityFactoryManager;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Jokser
 * Date: 28.05.12
 * Time: 12:25
 * To change this template use File | Settings | File Templates.
 */

public class EntityTableFormManager {

    public static EntityPropertyCaption getDefaultTableProperties (Class entityClass) {
        String entityName = entityClass.getSimpleName();
        List<EntityTablePropertiesEntity> list = EntityFactoryManager.getEntityTableProperties(entityName);
        int listSize = list.size();

        if (listSize == 0) return null;

        Object[] properties = new Object[listSize + 1];
        String[] captions = new String[listSize + 1];
        for (int i = 0; i < list.size(); i++) {
            properties [i] = list.get(i).getPropertyName();
            captions [i] = list.get(i).getRusCaption();
        }

        properties [listSize] = "details";
        captions [listSize] = "";
        return new EntityPropertyCaption(properties, captions);
    }

    public static EntityPropertyCaption getDefaultFormProperties (Class entityClass) {
        String entityName = entityClass.getSimpleName();
        List<EntityFormPropertiesEntity> list = EntityFactoryManager.getEntityFormProperties(entityName);
        int listSize = list.size();

        if (listSize == 0) return null;

        Object[] properties = new Object[listSize];
        String[] captions = new String[listSize];
        Integer[] required = new Integer[listSize];
        String[] descriptions = new String[listSize];

        for (int i = 0; i < list.size(); i++) {
            properties [i] = list.get(i).getPropertyName();
            captions [i] = list.get(i).getRusCaption();
            required [i] = list.get(i).getRequired();
            descriptions [i] = list.get(i).getDescription();
        }

        return new EntityPropertyCaption(properties, captions, required, descriptions);
    }

    public static Object [] getDefaultCatalogTableProperties () {
        return new Object[] {"id", "value"};
    }

    public static String [] getDefaultCatalogTableCaptions () {
        return new String [] {"ID", "Значение"};
    }


}